/*收款*/
$(".grids-item").on("click",function(){
	var _v = $("#_total").val();
	var _a = $(this).data('value');
	switch(_a){
		case "-":
		  if(_v != ''){
		  	 _v = _v.substr(0,_v.length-1);
		  }
		  break;
		case ".":
		  if(_v.indexOf(".") > 0){
		  	 return false;
		  }
		  if(_v == ''){
		  	 _v += "0"
		  }
		  _v += _a;
		  break;
		case "ok" :
			if($(".ok-btn").hasClass("disabled")){
				return false;
			}
			if(parseFloat(_v) <= 0 || isNaN(parseFloat(_v))){
				error("请输入金额");
				return false;
			}
			loading()
			location.href=$(this).data("href")+"?total="+_v
			return true;
		  break;
		 default :
		 	var s = _v.split(".");
		 	if(_v.lastIndexOf(".") > 0){
		 		if(s[1].length == 2){
		 			return false;
		 		}
		 	}else{
		 		if(s[0].length>=6){
			 		return false;
			 	}
		 	}

		    _v += _a;

	}
	if(parseFloat(_v) > 0 || isNaN(parseFloat(_v))){
		$(".ok-btn").removeClass("disabled");
	}else{
		$(".ok-btn").addClass("disabled");
	}
	//$(".grids-item").find(".ok-btn").text('sss')
	$("#_total").val(_v)
	$("#total-txt").text(_v);
})

/*要不提交*/
$("body").on("click",".ajax-submit",function(){
	var _this = $(this)
	if(_this.hasClass("disabled")){
		return false
	}
	_this.addClass("disabled")
	var _form = $("#_form");
	loading(30000)
	$.post(_form.attr("action"),_form.serialize(),function(res){
		_this.removeClass("disabled")
		closeLoad();
	})
})
function success(msg){
	var $toast = $('#toast-success');
	if ($toast.css('display') != 'none') return;
    $toast.fadeIn(100);
    setTimeout(function () {
        $toast.fadeOut(100);
    }, 2000);
    $("#toast-content").text(msg)
}
function error(msg){
	var $toast = $('#toast-error');
	if ($toast.css('display') != 'none') return;
    $toast.fadeIn(100);
    setTimeout(function () {
        $toast.fadeOut(100);
    }, 2000);
    $("#error-content").text(msg)
}
function closeLoad(){
	var $loadingToast = $('#loadingToast');
    if ($loadingToast.css('display') == 'none') return;

    $loadingToast.fadeOut(100);
}
function loading(timeout){
	var $loadingToast = $('#loadingToast');
    if ($loadingToast.css('display') != 'none') return;
    var time = timeout || 2000
    $loadingToast.fadeIn(100);
    setTimeout(function () {
        $loadingToast.fadeOut(100);
    }, time);
}
